import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../widgets/text_button.dart';
import '../../widgets/yz_text.dart';
import 'json_to_model_controller.dart';

class JsonToModelPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<JsonToModelController>(
        init: JsonToModelController(),
        builder: (controller) {
          return Scaffold(
              appBar: AppBar(
                title: Text('json转实体'),
              ),
              body: Container(
                  margin: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          MyTextField(
                            controller: controller.textEditingController,
                            width: 300,
                            height: windowHeight * 0.8,
                            maxLines: 30,
                            hintText: '请输入json数据',
                            textStyle: TextStyle(color: Colors.black),
                            isShowOutLine: false,
                            contentPadding: EdgeInsets.only(left: 8, top: 20),
                          ),
                          IconButton(
                              onPressed: () {
                                controller.transform();
                              },
                              icon: Icon(
                                  Icons.keyboard_double_arrow_right_rounded)),
                          Expanded(
                              child: Container(
                            height: windowHeight * 0.8,
                            child: TextField(
                              controller:
                                  controller.resultTextEditingController,
                              readOnly: true,
                              decoration: InputDecoration(
                                border: const OutlineInputBorder(),
                              ),
                              maxLines: 30,
                              style: TextStyle(
                                  color: Color(0xff0005FF),
                                  fontWeight: FontWeight.normal),
                            ),
                          ))
                        ],
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      Row(
                        children: [
                          MyTextField(
                            controller:
                                controller.classNameTextEditingController,
                            width: 100,
                            height: 40,
                            hintText: '类名',
                          ),
                          TextButton(
                              onPressed: () {
                                controller.clearZy();
                              },
                              child: Text(
                                '去除转义',
                                style: TextStyle(color: Colors.blueAccent),
                              )),
                          // TextButton(
                          //     onPressed: () {
                          //       controller.runCommand();
                          //     },
                          //     child: Text(
                          //       '序列化',
                          //       style: TextStyle(color: Colors.blueAccent),
                          //     )),
                          Spacer(),
                          Container(
                              height: 30,
                              child: Row(
                                children: [
                                  _textButton(width: 180, '复制全部', controller,
                                      onPressed: () {
                                    controller.copyCode();
                                  }),
                                  _textButton(width: 180, '清空', controller,
                                      onPressed: () {
                                    controller.clear();
                                  }),
                                ],
                              ))
                        ],
                      )
                    ],
                  )));
        });
  }

  _textButton(String text, JsonToModelController controller,
      {double width = 90, Function? onPressed}) {
    return Container(
        height: width,
        margin: EdgeInsets.only(left: 15, right: 20),
        alignment: Alignment.center,
        child: MyTextButton(
            text: text,
            confirm: () {
              onPressed?.call();
            },
            backgroundColor: Colors.deepPurpleAccent,
            textStyle: TextStyle(color: Colors.white)));
  }
}
